package com.heima.admin.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.heima.admin.service.AdminChannelService;
import com.heima.client.wemedia.IWemediaClient;
import com.heima.common.exception.CustomException;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import com.heima.model.common.pojos.wemedia.WmChannel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Description:
 * Author: Wzh
 * Date: 2024/8/3
 */
@Service
public class AdminChannelImpl implements AdminChannelService {

    @Autowired
    private IWemediaClient wemediaClient;

    /**
     * 查询所有频道
     *
     * @return
     */
    @Override
    public List<WmChannel> list() {
        //发起feign远程调用wemedia微服务查询频道列表
        ResponseResult channels = wemediaClient.channels();
        if (channels.getCode() == 200) {
            String jsonString = JSON.toJSONString(channels.getData());
            return JSONArray.parseArray(jsonString, WmChannel.class);
        }
        throw new CustomException(AppHttpCodeEnum.SERVER_ERROR);
    }
}

